<template>
  <div class="manage-stock">
    <div class="manage-stock-header">
      <div class="search-form">
        <search
          ref="mysearch"
          @doReset="doReset"
          @doQuery="doRefresh"
          :ruleform="form"
        >
          <template slot="top">
            <el-form-item label="型号" label-width="76px" class="label-name-col">
              <el-input v-model="form.partNumber" placeholder="请输入型号"></el-input>
            </el-form-item>
            <el-form-item label="品牌" label-width="76px" class="label-name-col">
              <el-input v-model="form.brand" placeholder="请输入品牌"></el-input>
            </el-form-item>
            <el-form-item label="创建日期" label-width="76px">
              <mydate
                @getSelectData="getCreateDate"
                :createDate="form.createDate"
              ></mydate>
            </el-form-item>
            <el-form-item label="库存所在地" label-width="76px">
              <el-select
                v-model="form.inventoryHome"
                placeholder="请选择"
                style="width: 98%"
              >
                <el-option
                  v-for="item in placeOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="状态" label-width="76px" class="label-name-col">
              <el-select
                v-model="form.status"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="价格类型" label-width="76px">
              <el-select
                v-model="form.unitPriceType"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in priceOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="阶梯名称" label-width="76px">
              <el-select
                v-model="form.ladderPriceId"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in allPriceList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </template>
          <div slot="foot"></div>
        </search>
      </div>
    </div>
    <div class="manage-stock-meduim">
      <el-button type="primary" @click="getEdit" :disabled="isdisabled"
        >编辑</el-button
      >
      <el-button
        type="primary"
        @click="putOnShelves"
        :disabled="isShelvesdisabled"
        >上架</el-button
      >
      <el-button type="primary" @click="lowerShelf" :disabled="isowerdisabled"
        >下架</el-button
      >
      <el-button type="primary" :disabled="isSetAdvdisabled" @click="setModel"
        >设为优势型号</el-button
      >
      <el-button type="primary" @click="getConcel" :disabled="isConceldisabled"
        >取消优势型号</el-button
      >
    
      <el-button type="primary" @click="getDel" :disabled="isdisabled"
        >删除</el-button
      >
      <el-button type="primary" @click="getPrice" :disabled="isPricedisabled"
        >阶梯价格配置</el-button
      >
      <el-button type="primary" @click="exportToExcel">批量导出</el-button>
      <el-button type="primary" @click="updateTime" :disabled="isdisabled"
        >更新库存时间</el-button
      >
    </div>
    <div class="manage-stock-footer">
      <!-- 表格 -->
      <myTable
        ref="mytable"
        class="table-box"
        :config="tableconfig"
        @handleSelectChange="handleSelectChange"
        @checkedAll="checkedAllVal"
        :checkedStatus="allParams.isAll"
      >
        <div slot="mytablebody"></div>
        <!-- 上架状态 -->
        <template v-slot:status="{ data }">
          <div class="status-box" v-if="data.status == 0">
            <p class="circle"></p>
            <p>已下架</p>
          </div>
          <div class="status-box" v-if="data.status == 1">
            <p class="circle-col"></p>
            <p>已上架</p>
          </div>
        </template>
        <!-- 品牌 -->
        <template v-slot:brand="{ data }">
          <div class="partNumber-box">
            <img
              src="@/assets/images/good.png"
              alt=""
              v-if="data.ifAdvantageBrand == 1"
            />
            <span v-if="data.ifAdvantageBrand == 0"></span>
            <p>{{ data.brand }}</p>
          </div>
        </template>
        <!-- 型号 -->
        <template v-slot:partNumber="{ data }">
          <div class="partNumber-box">
            <img
              src="@/assets/images/good.png"
              v-if="data.ifAdvantageModel == 1"
              alt=""
            />
            <span v-if="data.ifAdvantageModel == 0"></span>
            <p>{{ data.partNumber }}</p>
          </div>
        </template>
        <!-- 价格类型 -->
        <template v-slot:unitPriceType="{ data }">
          <p v-if="data.unitPriceType == 1" class="type-box">单一价格</p>
          <p v-if="data.unitPriceType == 2" class="type-box">阶梯价格</p>
        </template>
        <!-- 单价 -->
        <template v-slot:unitPrice="{ data }">
          <div class="price-box">
            <p v-if="data.unitPriceType == 1" class="pricetype-box">
              <span v-if="data.moq != '' && data.moq != null"> {{ data.moq }}</span><span v-if="data.moq == '' ||data.moq == null">-</span><span  v-if="data.unitPrice != null"> {{ data.unitPrice }}</span>
            </p>
            <div v-if="data.unitPriceType == 2" class="type-typebox">
              <el-popover placement="bottom" width="190" trigger="hover" v-if="data.unitPriceConfig.length > 0">
                <el-table :data="data.unitPriceConfig" >
                  <el-table-column
                    property="mq"
                    align="center"
                    label="起订量"
                  ></el-table-column>
                  <el-table-column
                    property="unitPrice"
                    align="center"
                    label="单价"
                  ></el-table-column>
                </el-table>
                <p class="type-look" slot="reference"><span v-if="data.unitPriceConfig[0].mq != '' && data.unitPriceConfig[0].mq != null">{{ data.unitPriceConfig[0].mq }}</span>
                  <span v-if="data.unitPriceConfig[0].mq == '' || data.unitPriceConfig[0].mq == null">—</span>
                  <span>{{ data.unitPriceConfig[0].unitPrice }} <img src="@/assets/images/eyes.svg" alt=""/></span></p>
              </el-popover>
            </div>
          </div>
        </template>
        <!-- 阶梯价格配置 -->
        <template v-slot:ladderPriceName="{ data }">
          <p v-if="data.ladderPriceName" class="type-box">
            {{ data.ladderPriceName }}
          </p>
          <p v-else class="type-box">-</p>
        </template>
        <!-- 起订量 -->
        <!-- <template v-slot:mqList="{ data }">
          <p v-for="val in data.mqList" class="type-box">{{ val }}</p>
        </template> -->
        <!-- 单价 -->
        <!-- <template v-slot:unitPriceList="{ data }">
          <p v-for="val in data.unitPriceList" class="type-box">{{ val }}</p>
        </template> -->
        <!-- 币种 -->
        <template v-slot:currency="{ data }">
          <p v-if="data.currency == 1" class="type-box">人民币</p>
          <p v-if="data.currency == 2" class="type-box">美元</p>
        </template>
        <!-- 包装 -->
        <template v-slot:packing="{ data }">
          <p v-if="data.packing == 1" class="type-box">卷带(TR)</p>
          <p v-if="data.packing == 2" class="type-box">Pack</p>
        </template>
        <!-- 库存所在地 -->
        <template v-slot:inventoryHome="{ data }">
          <p v-if="data.inventoryHome == 1" class="type-box">中国大陆</p>
          <p v-if="data.inventoryHome == 2" class="type-box">中国香港</p>
        </template>
        <!-- 操作 -->
        <template v-slot:operation="{ data }">
          <p class="oper-tit" v-if="data.ifAdvantageModel == 0" @click="setAdanModel(data)">设为优势型号</p>
          <p class="oper-tit" v-if="data.ifAdvantageModel == 1" @click="concelModel(data)">取消优势型号</p>
        </template>
      </myTable>
    </div>
    <!-- 删除 -->
    <el-dialog
      title="删除"
      :visible.sync="dialogDelVisible"
      width="25%"
      class="cancel-dialog"
    >
      <div class="del-box">
        <i class="el-icon-delete del-icon"></i>
        <p class="del-content">您确认删除该库存数据吗？</p>
        <!-- <p class="del-tips">(删除后无法获得该库存数据的报价任务)</p> -->
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="getDelSubmit()">确认</el-button>
        <el-button @click="dialogDelVisible = false" class="resletBtn">取消</el-button>
      </div>
    </el-dialog>
    <!-- 更新时间 -->
    <el-dialog
      title="更新时间"
      :visible.sync="dialogUpdateVisible"
      width="20%"
      class="cancel-dialog"
    >
      <div class="del-box">
        <img src="@/assets/images/update.png" alt="" />
        <p class="update-content">您确认要更新库存时间吗？</p>
        <p class="tips">更新时间后库存日期会变为当前日期</p>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="getUpdateSubmit()">确认</el-button>
        <el-button @click="dialogUpdateVisible = false" class="resletBtn">取消</el-button>
      </div>
    </el-dialog>
    <!-- 编辑 -->
    <el-drawer
      title="编辑"
      :visible.sync="dialogEditVisible"
      @close="closeEdit"
      class="add-dialog"
      size="26%"
    >
      <el-form :model="editForm" class="editForm" :rules="rules" ref="editForm">
        <!-- <el-row>
          <el-col :span="10"> -->
            <el-form-item
              label="型号："
              :label-width="formLabelWidth"
              prop="partNumber"
            >
              <el-input
                v-model="editForm.partNumber"
                autocomplete="off"
                :disabled="isInputdisabled"
              ></el-input>
            </el-form-item>
          <!-- </el-col>
          <el-col :span="10"> -->
            <el-form-item
              label="品牌："
              :label-width="formLabelWidth"
              prop="brand"
            >
              <el-input
                v-model="editForm.brand"
                autocomplete="off"
                :disabled="isInputdisabled"
              ></el-input>
            </el-form-item>
          <!-- </el-col>
        </el-row> -->
        <!-- <el-row>
          <el-col :span="10"> -->
            <el-form-item
              label="数量："
              :label-width="formLabelWidth"
              prop="count"
            >
              <el-input
                v-model="editForm.count"
                autocomplete="off"
                @keyup.native="
                  editForm.count = editForm.count.replace(/[^\d]/g, '')
                "
              ></el-input>
            </el-form-item>
          <!-- </el-col>
          <el-col :span="10"> -->
            <el-form-item
              label="封装："
              :label-width="formLabelWidth"
              prop="packages"
            >
              <el-input
                v-model="editForm.packages"
                autocomplete="off"
                :disabled="isPackDisadled"
              ></el-input>
            </el-form-item>
          <!-- </el-col>
        </el-row>
        <el-row> -->
          <!-- <el-col :span="10"> -->
            <el-form-item
              label="批次："
              :label-width="formLabelWidth"
              prop="batch"
            >
              <el-input v-model="editForm.batch" autocomplete="off"></el-input>
            </el-form-item>
          <!-- </el-col>
          <el-col :span="10"> -->
            <el-form-item
              label="包装："
              :label-width="formLabelWidth"
              prop="packing"
            >
              <el-select
                v-model="editForm.packing"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in packingOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="parseInt(item.value)"
                >
                </el-option>
              </el-select>
            </el-form-item>
          <!-- </el-col>
        </el-row>
        <el-row>
          <el-col :span="10"> -->
            <el-form-item
              label="最小起订量："
              :label-width="formLabelWidth"
              prop="moq"
            >
              <el-input
                v-model="editForm.moq"
                autocomplete="off"
                @keyup.native="
                  editForm.moq = editForm.moq.replace(/[^\d]/g, '')
                "
              ></el-input>
            </el-form-item>
          <!-- </el-col>
          <el-col :span="10"> -->
            <el-form-item
              label="最小包装量："
              :label-width="formLabelWidth"
              prop="mpq"
            >
              <el-input
                v-model="editForm.mpq"
                autocomplete="off"
                @keyup.native="
                  editForm.mpq = editForm.mpq.replace(/[^\d]/g, '')
                "
              ></el-input>
            </el-form-item>
          <!-- </el-col>
        </el-row>
        <el-row>
          <el-col :span="10"> -->
            <el-form-item
              label="币种："
              :label-width="formLabelWidth"
              prop="currency"
            >
              <el-select
                v-model="editForm.currency"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in currencyOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="parseInt(item.value)"
                >
                </el-option>
              </el-select>
            </el-form-item>
          <!-- </el-col>
          <el-col :span="10"> -->
            <el-form-item
              label="库存所在地："
              :label-width="formLabelWidth"
              prop="inventoryHome"
            >
              <el-select
                v-model="editForm.inventoryHome"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in placeOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="parseInt(item.value)"
                >
                </el-option>
              </el-select>
            </el-form-item>
          <!-- </el-col>
        </el-row> -->
        <el-form-item label="单价：" :label-width="formLabelWidth">
          <el-radio-group v-model="editForm.unitPriceType">
            <el-radio :label="1">单一价格</el-radio>
            <el-radio :label="2">阶梯价格</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="价格："
          :label-width="formLabelWidth"
          v-if="editForm.unitPriceType == 1"
        >
          <!-- <el-col :span="8"> -->
            <el-input
              v-model="editForm.unitPrice"
              autocomplete="off"
              @keyup.native="
                editForm.unitPrice =
                  editForm.unitPrice.match(/^\d*(\.?\d{0,6})/g)[0] || null
              "
            ></el-input>
          <!-- </el-col> -->
        </el-form-item>
        <el-form-item
          label="最低阶梯价格："
          :label-width="formLabelWidth"
          v-if="editForm.unitPriceType == 2"
        >
            <el-input
              v-model="editForm.unitPrice"
              autocomplete="off"
              @keyup.native="
                editForm.unitPrice =
                  editForm.unitPrice.match(/^\d*(\.?\d{0,6})/g)[0] || null
              "
            ></el-input>
          <!-- </el-col> -->
        </el-form-item>
        <el-form-item
          label="阶梯价格配置方案："
          :label-width="formLabelWidth"
          v-if="editForm.unitPriceType == 2"
        >
          <!-- <el-col :span="8"> -->
            <el-select
              v-model="editForm.ladderPriceId"
              placeholder="请选择"
              style="width: 100%"
            >
              <el-option
                v-for="item in editForm.allLadderPriceInfoPojoList"
                :key="item.id"
                :label="item.name"
                :value="parseInt(item.id)"
              >
                <el-popover placement="right" width="200" trigger="hover">
                  <el-table :data="item.ladderPriceConfigData">
                    <el-table-column
                      property="mq"
                      align="center"
                      label="起订量"
                    ></el-table-column>
                    <el-table-column
                      property="lower"
                      align="center"
                      label="降比"
                    ></el-table-column>
                  </el-table>
                  <el-button
                    slot="reference"
                    type="text"
                    style="width: 100%; color: black"
                  >
                    <span style="float: left">{{ item.name }}</span>
                  </el-button>
                </el-popover>
              </el-option>
            </el-select>
          <!-- </el-col> -->
        </el-form-item>
      </el-form>
      <div class="demo-drawer__footer">
        <el-button type="primary" @click="getEditSubmit('editForm')"
          >确认</el-button
        >
        <el-button @click="dialogEditVisible = false" class="resletBtn">取消</el-button>
      </div>
    </el-drawer>
    <!-- 阶梯价格配置 -->
    <el-dialog
      title="阶梯价格配置"
      :visible.sync="dialogPriceVisible"
      @close="closePrice"
      class="price-dialog"
      width="60%"
    >
      <el-radio-group v-model="price.tabPosition" @input="getInverntoryDate(allParams)">
        <el-radio-button label="1">按起订量配置</el-radio-button>
        <el-radio-button label="2">按单价配置</el-radio-button>
      </el-radio-group>
      <div  >
        <div class="header" v-if="price.tabPosition == 1">
          批量配置
          <el-select
            v-model="price.ladderPriceId"
            placeholder="请选择"
            class="select-model"
          >
            <el-option
              v-for="item in pricebox"
              :key="item.id"
              :label="item.name"
              :value="parseInt(item.id)"
            >
              <el-popover placement="right" width="200" trigger="hover">
                <el-table :data="item.ladderPriceConfigData" >
                  <el-table-column
                    property="mq"
                    align="center"
                    label="起订量"
                  ></el-table-column>
                  <el-table-column
                    property="lower"
                    align="center"
                    label="降比"
                  ></el-table-column>
                </el-table>
                <el-button
                  slot="reference"
                  type="text"
                  style="width: 100%; color: black"
                >
                  <span style="float: left">{{ item.name }}</span>
                </el-button>
              </el-popover>
            </el-option>
          </el-select>
        </div>
        <div class="header" v-if="price.tabPosition == 2">
          批量配置
          <el-select
            v-model="price.ladderAmountPriceId"
            placeholder="请选择"
            class="select-model"
          >
            <el-option
              v-for="item in PriceByAmount"
              :key="item.id"
              :label="item.name"
              :value="parseInt(item.id)"
            >
              <el-popover placement="right" width="340" trigger="hover" @show="showPriceDate(item.ladderPriceConfigData)">
                <el-table :data="item.ladderPriceConfigData" :span-method="objectSpanMethod"  border  max-height="500">
                  <el-table-column
                    property="maxPrice"
                    align="center"
                    label="单价"
                  >
                  <template slot-scope="scope">
                    <div >
                      <span v-if="scope.row.minPrice">{{ scope.row.minPrice }}</span>
                      <span  v-if="scope.row.minPrice"> ＜ </span><span>单价</span><span  v-if="scope.row.maxPrice"> ≤</span>
                      <span v-if="scope.row.maxPrice">{{ scope.row.maxPrice }}</span>
                    </div>
                  </template>
                  </el-table-column>
                  <el-table-column
                    property="mq"
                    align="center"
                    label="起订量"
                  ></el-table-column>
                  <el-table-column
                    property="lower"
                    align="center"
                    label="降比"
                  ></el-table-column>
                </el-table>
                <el-button
                  slot="reference"
                  type="text"
                  style="width: 100%; color: black"
                >
                  <span style="float: left">{{ item.name }}</span>
                </el-button>
              </el-popover>
            </el-option>
          </el-select>
        </div>
        <div v-if="price.tabPosition == 2" class="currency-box">
          <el-radio v-model="currency" :label="1">人民币</el-radio>
          <el-radio v-model="currency" :label="2">美元</el-radio>
        </div>
        <el-form :model="priceValidateForm" ref="priceValidateForm">
          <el-table
            ref="multipleTable"
            :data="priceValidateForm.tableData"
            tooltip-effect="dark"
            :height="350"
            style="width: 100%"
          >
            <el-table-column label="型号">
              <template slot-scope="scope">{{ scope.row.partNumber }}</template>
            </el-table-column>
            <el-table-column prop="brand" label="品牌" >
            </el-table-column>
            <el-table-column prop="count" label="数量" width="120">
            </el-table-column>
            <el-table-column prop="batch" label="批次" width="120">
            </el-table-column>
            <el-table-column prop="moq" label="最小起订量" width="120">
            </el-table-column>
            <el-table-column prop="unitPrice" label="最低阶梯价" width="100">
            </el-table-column>
            <el-table-column prop="currency" label="币种" width="100">
              <template slot-scope="scope">
                <p v-if="scope.row.currency == 1">人民币</p>
                <p v-if="scope.row.currency == 2">美元</p>
              </template>
            </el-table-column>
            <el-table-column prop="ladderPriceId" label="阶梯价格配置"  v-if="price.tabPosition == 1">
              <template slot-scope="scope">
                <el-form-item
                  :prop="'tableData.' + scope.$index + '.ladderPriceId'"
                >
                  <el-select
                    v-model="scope.row.ladderPriceId"
                    placeholder="请选择"
                    :filter-method="selectladderPriceId(scope.row.ladderPriceId,scope.row.ladderPriceInfoByMoqRespPojoList,scope.$index)"
                  >
                    <el-option
                      v-for="item in scope.row.ladderPriceInfoByMoqRespPojoList"
                      :key="item.id"
                      :label="item.name"
                      :value="parseInt(item.id)"
                    >
                      <el-popover placement="right" width="200" trigger="hover">
                        <el-table :data="item.ladderPriceConfigData" max-height="500">
                          <el-table-column
                            property="mq"
                            align="center"
                            label="起订量"
                          ></el-table-column>
                          <el-table-column
                            v-if="item.ladderPriceConfigData[0].lower&&item.ladderPriceConfigData[0].unitPrice == ''"
                            property="lower"
                            align="center"
                            label="降比"
                          ></el-table-column>
                          <el-table-column
                            v-if="item.ladderPriceConfigData[0].unitPrice"
                            property="unitPrice"
                            align="center"
                            label="阶梯价格"
                          ></el-table-column>
                        </el-table>
                        <el-button
                          slot="reference"
                          type="text"
                          style="width: 100%; color: black"
                        >
                          <span style="float: left">{{ item.name }}</span>
                        </el-button>
                      </el-popover>
                    </el-option>
                  </el-select>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column prop="ladderPriceId" label="阶梯价格配置 "  v-if="price.tabPosition == 2">
              <template slot-scope="scope">
                <el-form-item
                  :prop="'tableData.' + scope.$index + '.ladderPriceId'"
                >
                  <el-select
                    v-model="scope.row.ladderPriceId"
                    placeholder="请选择"
                    :filter-method="selectladderPriceId(scope.row.ladderPriceId,scope.row.ladderPriceInfoByAmountRespPojoList,scope.$index)"
                  >
                    <el-option
                      v-for="item in scope.row.ladderPriceInfoByAmountRespPojoList"
                      :key="item.id"
                      :label="item.name"
                      :value="parseInt(item.id)"
                    >
                      <el-popover placement="right" width="340" trigger="hover" @show="showTablePriceDate(item.ladderPriceConfigData)">
                        <el-table :data="item.ladderPriceConfigData" :span-method="objectTableSpanMethod" border max-height="500">
                          <el-table-column
                            prop="maxPrice"
                            align="center"
                            label="单价"
                          >
                          <template slot-scope="scope">
                            <div >
                              <span v-if="scope.row.minPrice">{{ scope.row.minPrice }}</span>
                              <span  v-if="scope.row.minPrice"> ＜ </span><span>单价</span><span  v-if="scope.row.maxPrice"> ≤</span>
                              <span v-if="scope.row.maxPrice">{{ scope.row.maxPrice }}</span>
                            </div>
                          </template>
                          </el-table-column>
                          <el-table-column
                            prop="mq"
                            align="center"
                            label="起订量"
                          ></el-table-column>
                         
                          <el-table-column
                           v-if="item.ladderPriceConfigData[0] != undefined && item.ladderPriceConfigData[0].unitPrice == ''"
                            prop="lower"
                            align="center"
                            label="降比"
                          >
                        </el-table-column>
                          <el-table-column
                            v-if="item.ladderPriceConfigData[0] != undefined && item.ladderPriceConfigData[0].unitPrice"
                            prop="unitPrice"
                            align="center"
                            label="阶梯价格"
                          ></el-table-column>
                        </el-table>
                        <el-button
                          slot="reference"
                          type="text"
                          style="width: 100%; color: black"
                        >
                          <span style="float: left">{{ item.name }}</span>
                        </el-button>
                      </el-popover>
                    </el-option>
                  </el-select>
                </el-form-item>
              </template>
            </el-table-column>
          </el-table>
          <div class="tips-box">
            <p>提示：1、所配置阶梯价格的最小起订量必须小于所选型号的最小起订量才能配置成功</p>
            <P>2、批量配置只能对符合规则的型号配置，若不成功请手动选择</P>
          </div>
          <div class="dialog-footer">
            <el-button type="primary" @click="getPriceSubmit('priceValidateForm')"
              >确认</el-button
            >
            <el-button @click="dialogPriceVisible = false" class="resletBtn">取消</el-button>
          </div>
        </el-form>
      </div>
    </el-dialog>
    <!-- 设为优势型号 -->
    <el-dialog
      title="设为优势型号"
      :visible.sync="dialogApplyVisible"
      width="36.4%"
      class="apply-dialog"
      @close="closeApply"
    >
      <div class="applyform">
        <el-form :model="applyform" :rules="applyRules" ref="applyform">
          <el-form-item label="有效期：" :label-width="formLabelWidth1" required>
            <el-row>
                <el-col :span="11">
                    <el-form-item prop="startDate">
                        <el-date-picker
                        v-model="applyform.validityDateStart"
                        type="date"
                        placeholder="选择开始日期"
                        :picker-options="setStartDateDisabled"
                        value-format="yyyy-MM-dd"
                        >
                    </el-date-picker>
                </el-form-item>
                </el-col>
                <el-col :span="2">
                    <span class="line">—</span>
                </el-col>
                <el-col :span="11">
                    <el-form-item prop="endDate">
                        <el-date-picker
                        v-model="applyform.validityDateEnd"
                        type="date"
                        :picker-options="setFinshDateisabled"
                        value-format="yyyy-MM-dd"
                        placeholder="选择结束日期"
                        >
                        </el-date-picker>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form-item>
          <el-form-item
            label="备注："
            :label-width="formLabelWidth1"
            prop="remark"
          >
            <el-input
              type="textarea"
              v-model="applyform.remark"
              maxlength="100"
              show-word-limit
            >
            </el-input>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="getApplySubmit('applyform')"
          >确认</el-button
        >
        <el-button @click="dialogApplyVisible = false" class="resletBtn">取消</el-button>
      </div>
    </el-dialog>
    <!-- 取消优势型号 -->
    <el-dialog
      title="取消"
      :visible.sync="dialogCancelVisible"
      width="25%"
      class="cancel-dialog"
    >
      <div class="del-box">
        <img src="@/assets/images/concel.png" alt="" class="concel-icon" />
        <p class="del-content">您确认取消该优势型号吗？</p>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="getaCancelSubmit()">确 认</el-button>
        <el-button @click="dialogCancelVisible = false" class="resletBtn">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import mydate from "@/components/Date/index.vue";
import search from "@/components/Search/index.vue";
import {
  queryInventory,
  priceList,
  LadderPriceByMoq,
  LadderPriceByAmount,
  getLadderPriceData,
  deleteInventory,
  getInventoryList,
  batchExport,
  updateInventoryList,
  updateStatusList,
  updateInventoryDate,
  setLadderPrice,
  updateAdvantageStatus,
  allLadderList,
  cancleAdvantageModel,
} from "@/api/stock";
import { off } from "process";
export default {
  name: "manageStock",
  components: {
    mydate,
    search,
  },
  data() {
    return {
      form: {
        brand: "",
        endDate: "",
        id: "",
        inventoryHome: "",
        ladderPriceId: "",
        partNumber: "",
        startDate: "",
        status: "",
        unitPriceType: "",
        createDate: [],
        pageNo: 1,
        pageSize: 20,
      },
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一年",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 365);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      options: [
        {
          value: "",
          label: "全部",
        },
        {
          value: "0",
          label: "已下架",
        },
        {
          value: "1",
          label: "已上架",
        },
      ],
      placeOptions: [
        {
          value: "1",
          label: "中国大陆",
        },
        {
          value: "2",
          label: "中国香港",
        },
      ],
      currencyOptions: [
        {
          value: "1",
          label: "人民币",
        },
        {
          value: "2",
          label: "美元",
        },
      ],
      packingOptions: [
        {
          value: "1",
          label: "卷带(TR)",
        },
        {
          value: "2",
          label: "Pack",
        },
      ],
      priceOptions: [
        {
          value: "1",
          label: "单一价格",
        },
        {
          value: "2",
          label: "阶梯价格",
        },
      ],
      isdisabled: true,
      isPricedisabled:true,
      tableconfig: {
        loading: false,
        isselection: true,
        ispagination: true,
        isfixed: true,
        tabledata: [],
        isindex: true,
        thead: [
          {
            sort: null,
            label: "状态",
            prop: "status",
            width: 75,
            type: "slot",
            fixed: true,
          },
          {
            sort: null,
            label: "型号",
            prop: "partNumber",
            type: "slot",
            width:320,
            fixed: true,
          },
          {
            sort: null,
            label: "品牌",
            prop: "brand",
            type: "slot",
            width:250,
            fixed: true,
          },
          { sort: null, label: "数量", prop: "count",
           width: 80, 
           fixed: true },
          { sort: null, label: "批次", prop: "batch",
         
          },
          { sort: null, label: "封装", prop: "packages",
        
          },
            {
            sort: null,
            label: "阶梯名称",
            prop: "ladderPriceName",
            type: "slot",
          },
          {
            sort: null,
            label: "价格类型",
            prop: "unitPriceType",
            type: "slot",
          },
        
          {
            sort: null,
            label: "起订量/单价",
            prop: "unitPrice",
            width: 160,
            type: "slot",
          },
          { sort: null, label: "最小包装量", prop: "mpq", 
         },
          {
            sort: null,
            label: "库存所在地",
            prop: "inventoryHome",
            type: "slot",
          },
          { sort: null, label: "更新日期", prop: "modifyDate", 
         },
        ],
        // checkedAll: false, //全选所有
        checkedPage: false, //全选本页
        currentpage: 1,
        pagesize: 20,
        total: 3,
      },
      setStartDateDisabled:{
          disabledDate: (time) => {
              if (this.applyform.validityDateEnd) {
                  return  Date.now() < time.getTime() >= new Date(this.applyform.validityDateEnd).getTime();
              }else{
                  return  time.getTime() < Date.now() - 86400000;
              }
          },
      },
      setFinshDateisabled:{
          disabledDate: (time) => {
              if(this.applyform.validityDateStart){
                  return time.getTime() < new Date(this.applyform.validityDateStart).getTime();
              }else{
                  return time.getTime()
              }
          }
      },
      PriceByAmount:[],
      currency:1,
      theadList: [],
      theadPriceList: [],
      // 当前选中的行数据
      selectrow: [],
      pricebox: [],
      priceStepbox:[],
      allParams: {
        brand: "",
        endDate: "",
        createDate: "",
        inventoryHome: "",
        ladderPriceId: "",
        partNumber: "",
        startDate: "",
        status: "",
        unitPriceType: "",
        idList: [],
        isAll: false,
        updateStatus: "",
        operateType:'',
        validityDateEnd:'',
        validityDateStart:'',
        remark:'',
      },
      brandId: [],
      priceListbox: [],
      editForm: {
        batch: "",
        count: "",
        partNumber: "",
        brand: "",
        inventoryHome: "",
        currency: "",
        unitPriceType: "",
        unitPrice: "",
        ladderPriceId: "",
        moq: "",
        mpq: "",
        packages: "",
        id: "",
        packing: "",
      },
      rules: {
        partNumber: [
          { required: true, message: "请填写型号", trigger: "blur" },
        ],
        count: [{ required: true, message: "请填写库存数量", trigger: "blur" }],
        brand: [{ required: true, message: "请填写品牌", trigger: "blur" }],
        batch: [{ required: true, message: "请填写批次", trigger: "blur" }],
      },
      laddrules: {
        ladderPriceId: [
          {
            required: true,
            message: "请选择阶梯价格配置项",
            trigger: "change",
          },
        ],
      },
      isInputdisabled: true,
      isPackDisadled:true,
      priceValidateForm: {
        tableData: [],
      },
      // tableData:[],
      price: {
        batch: true,
        ladderPriceId: "",
        ladderAmountPriceId: "",
        tabPosition:'1',
      },
      inventoryList: [{}],
      // isPriceIsshow:false,
      dialogTableVisible: false,
      dialogUpdateVisible: false,
      dialogDelVisible: false,
      dialogEditVisible: false,
      dialogPriceVisible: false,
      dialogCancelVisible: false,
      dialogApplyVisible: false,
      formLabelWidth: "134px",
      formLabelWidth1:'70px',
      applyform: {
        validityDateEnd:'',
        validityDateStart:"",
        createDate: [],
        remark: "",
      },
      applyRules: {
        createDate: [
          { required: true, message: "请选择有效期", trigger: "change" },
        ],
      },
      isShelvesdisabled: true, //禁止已上架
      isowerdisabled: true, //禁止下架
      isSetAdvdisabled:true,//禁止设置优势型号
      isConceldisabled:true,//禁止取消优势型号
      priceAmountDate:'',
      priceTableAmountDate:"",//按单价配置的表格里面的数据
      allPriceList:[],
    };
  },
  created() {
    this.doQuery();
    allLadderList().then(res=>{
      // console.log(res,'uuuu');
      if(res.success){
        this.allPriceList = res.result
      }
    })
    // console.log(this.tableconfig.thead, "this.tableconfig.thead");
  },
  methods: {
    getCreateDate(date) {
      this.form.createDate = date;
    },
    handleSelectChange(section) {
      this.selectrow = section;
      if (this.selectrow.length >= 1) {
        this.isdisabled = false;
        // this.isPricedisabled = false;
      }else{
        this.isdisabled = true;
        this.isPricedisabled = true;
      }
      // 阶梯价格配置的数据逻辑
      if(this.selectrow.length >= 1 && !this.allParams.isAll){
        this.isPricedisabled = false;
      }else{
        this.isPricedisabled = true;
      }
      let arr = [];
      this.selectrow.filter((item) => {
        arr.push(item.status);
      });
      let setArr = [...new Set(arr)];
      if (setArr.length == 1) {
        if (setArr[0] == 1) {
          this.isowerdisabled = false;
          this.isShelvesdisabled = true;
        } else if (setArr[0] == 0) {
          this.isShelvesdisabled = false;
          this.isowerdisabled = true;
        }
      } else if (setArr.length >= 1) {
        this.isowerdisabled = false;
        this.isShelvesdisabled = false;
      } else {
        this.isShelvesdisabled = true;
        this.isowerdisabled = true;
      }
     
      let advaArr = [];
      this.selectrow.filter((item) => {
        advaArr.push(item.ifAdvantageModel);
      });
      let setAdvaArr = [...new Set(advaArr)];
      // console.log(setAdvaArr,'setAdvaArrsetAdvaArrsetAdvaArr');
      if (setAdvaArr.length == 1) {
        if (setAdvaArr[0] == 1) {
          this.isConceldisabled = false;
          this.isSetAdvdisabled = true;
        } else if (setAdvaArr[0] == 0) {
          this.isSetAdvdisabled = false;
          this.isConceldisabled = true;
        }
      } else if (setAdvaArr.length >= 1) {
        this.isConceldisabled = false;
        this.isSetAdvdisabled = false;
      } else {
        this.isSetAdvdisabled = true;
        this.isConceldisabled = true;
      }
    },
    checkedAllVal(val) {
      console.log(val, "checkedAllVal");
      this.allParams.isAll = val;
      // this.shelvesParams.isAll = val;
    },
    // 重置搜索
    doReset() {
      // console.log(Object.keys(this.form).slice(0,-2),'this.ruleForm');
      Object.keys(this.form)
        .slice(0, -2)
        .map((x) => {
          this.form[x] = "";
        });
      this.form.createDate = [];
      // console.log(this.form,'this.ruleForm.pageSize');
      // this.$message({
      //   message: "已重置",
      //   type: "success",
      // });
      this.doRefresh();
    },
    // 刷新
    doRefresh() {
      //页码从第一页开始
      this.tableconfig.currentpage = 1;
      this.form.pageNo = 1;
      //表格回到顶部
      this.$refs.mytable.$emit("handleGoTop");
      this.doQuery();
    },
    //搜索
    async doQuery() {
      // 获取表格
      this.tableconfig.loading = true;
      this.tableconfig.currentpage = this.form.pageNo;
      this.tableconfig.pagesize = this.form.pageSize;
      this.form.startDate = this.form.createDate[0];
      this.form.endDate = this.form.createDate[1];
      let data1 = await queryInventory(this.form);
      if (data1.success) {
        this.tableconfig.total = data1.result.count;
        this.tableconfig.tabledata = data1.result.data;
        console.log(this.tableconfig.tabledata,'this.tableconfig.tabledatathis.tableconfig.tabledata');
       this.tableconfig.tabledata.map((item,index)=>{
        if(item.unitPriceConfig != null && item.unitPriceConfig.length >0){
          item.unitPriceConfig = item.unitPriceConfig.map(val=>{
          val.unitPrice = parseFloat(val.unitPrice)
          if(Number.isInteger(val.unitPrice)){
            val.unitPrice += '.00'
          }
          if(item.currency == 1){
            val.unitPrice = '¥' + val.unitPrice;
          }
          if(item.currency == 2){
            val.unitPrice = '$' + val.unitPrice;
          }
          return val;
        })
        }
        if(item.unitPriceType == 1 && item.unitPrice != null){
          item.unitPrice = parseFloat(item.unitPrice);
          if(Number.isInteger(item.unitPrice)){
            item.unitPrice += '.00'
          }
          if(item.currency == 1){
            item.unitPrice = '¥' + item.unitPrice;
          }
          if(item.currency == 2){
            item.unitPrice = '$' + item.unitPrice;
          }
          return item.unitPrice;
        }
        
        })
        // console.log( this.tableconfig.tabledata,' this.tableconfig.tabledata');
      }
      this.tableconfig.loading = false;
    },
    // 页码数更新
    handleSizeChange(val) {
      this.form.pageNo = 1;
      this.form.pageSize = val;
      this.doQuery();
      //表格回到顶部
      this.$refs.mytable.$emit("handleGoTop");
    },
    // 当前页码更新
    handleCurrentChange(val) {
      this.form.pageNo = val;
      console.log(this.form.pageNo, "this.tableconfig.currentpage");
      this.doQuery();
      //表格回到顶部
      this.$refs.mytable.$emit("handleGoTop");
    },
    selectladderPriceId(val,arr,index){
      if(val != ''){
        let arrbox='';
        arrbox = arr.find(ladditem=>{
          return ladditem.id == val;  // arrbox.push(ladditem.id)
        })
        console.log(arrbox,index,' arrbox arrbox arrbox');
        if(arrbox == undefined){
          this.priceValidateForm.tableData[index].ladderPriceId = '';
        }
      }
      
    },
    getLook(data) {
      // this.dialogTableVisible = true;
      console.log(data, "datadddddd");
      this.priceListbox = data.unitPriceList;
    },
    // 设置优势型号
    setAdanModel(data){
     console.log(data,'555555555');
     this.dialogApplyVisible = true;
     this.brandId.push(data.id);
    },
    concelModel(data){
      console.log(data,'333333333333');
      this.dialogCancelVisible = true;
      this.brandId.push(data.id);
    },
    setModel() {
      if (this.selectrow.length >= 1) {
        let arr = [];
        let advArr = [];
        this.selectrow.map((val) => {
          arr.push(val.id);
          advArr.push(val.ifAdvantageModel);
        })
        let setArr = [...new Set(arr)];
        if (setArr.length > 1) {
          this.$message.warning("该库存信息无法操作");
          return false;
        }
        this.brandId = arr;
        // console.log(this.brandId, "this.brandId");
        this.dialogApplyVisible = true;
      } else {
        this.$message.warning("请选中至少一行的库存信息进行操作");
      }
    },
    getApplySubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.allParams.inventoryHome = this.form.inventoryHome;
          this.allParams.status = this.form.status;
          // this.form.startDate = this.form.createDate[0];
          // this.form.endDate = this.form.createDate[1];
          this.allParams.startDate = this.form.startDate;
          this.allParams.endDate = this.form.endDate;
          this.allParams.ladderPriceId = this.form.ladderPriceId;
          this.allParams.unitPriceType = this.form.unitPriceType;
          this.allParams.brand = this.form.brand;
          this.allParams.partNumber = this.form.partNumber;
          this.allParams.idList = this.brandId;
          this.allParams.operateType = 1;
          this.allParams.validityDateStart = this.applyform.validityDateStart;
          this.allParams.validityDateEnd = this.applyform.validityDateEnd;
          this.allParams.remark = this.applyform.remark;
          updateAdvantageStatus(this.allParams).then((res) => {
            if (res.success) {
              if(res.result){
                this.$message.success("此优势型号正在审核！");
                this.dialogApplyVisible = false;
                this.allParams.startDate = "";
                this.allParams.endDate = "";
                this.allParams.status = "";
                this.allParams.inventoryHome = "";
                this.allParams.ladderPriceId = "";
                this.allParams.unitPriceType = "";
                this.allParams.brand = "";
                this.allParams.idList = [];
                this.allParams.partNumber = "";
                this.allParams.isAll = false;
                this.allParams.operateType='';
                this.allParams.validityDateStart = "";
                this.allParams.validityDateEnd = "";
                this.allParams.remark = "";
                this.brandId = [];
                this.doQuery();
              }else{
                this.$message.error(res.message)
              }
              
            }
          });
        } else {
          return false;
        }
      });
    },
    // 取消
    getConcel() {
      if (this.selectrow.length > 0) {
        let arr = [];
        let advArr = [];
        this.selectrow.map((val) => {
          arr.push(val.id);
          advArr.push(val.ifAdvantageModel)
        });
        let setArr = [...new Set(arr)];
        if (setArr.length > 1) {
          this.$message.warning("该库存信息无法操作");
          return false;
        }
        this.brandId = arr;
        this.dialogCancelVisible = true;
      }else {
        this.$message.warning("请选中至少一行的库存信息进行操作");
      }
    },
    getaCancelSubmit() {
          this.allParams.inventoryHome = this.form.inventoryHome;
          this.allParams.status = this.form.status;
          this.form.startDate = this.form.createDate[0];
          this.form.endDate = this.form.createDate[1];
          this.allParams.startDate = this.form.startDate;
          this.allParams.endDate = this.form.endDate;
          this.allParams.ladderPriceId = this.form.ladderPriceId;
          this.allParams.unitPriceType = this.form.unitPriceType;
          this.allParams.brand = this.form.brand;
          this.allParams.partNumber = this.form.partNumber;
          this.allParams.idList = this.brandId;
          this.allParams.operateType = 0;
          this.allParams.validityDateStart = "";
          this.allParams.validityDateEnd = "";
          this.allParams.remark = "";
      updateAdvantageStatus(this.allParams).then((res) => {
        if (res.success) {
          if(res.result){
            this.$message.success("选中的库存信息的优势型号已无效");
            this.dialogCancelVisible = false;
            this.allParams.startDate = "";
            this.allParams.endDate = "";
            this.allParams.status = "";
            this.allParams.inventoryHome = "";
            this.allParams.ladderPriceId = "";
            this.allParams.unitPriceType = "";
            this.allParams.brand = "";
            this.allParams.idList = [];
            this.allParams.partNumber = "";
            this.allParams.isAll = false;
            this.allParams.operateType='';
            this.brandId = [];
            this.doQuery();
          }else{
            this.$message.error(res.message)
          }
         
        } else {
          this.$message.error(res.message);
        }
      });
    },
    //删除
    getDel() {
      if (this.selectrow.length >= 1) {
        let arr = [];
        this.selectrow.map((val) => {
          arr.push(val.id);
        });
        this.dialogDelVisible = true;
        this.brandId = arr;
      }
    },
    getDelSubmit() {
      this.allParams.inventoryHome = this.form.inventoryHome;
      this.allParams.status = this.form.status;
      this.form.startDate = this.form.createDate[0];
      this.form.endDate = this.form.createDate[1];
      this.allParams.startDate = this.form.startDate;
      this.allParams.endDate = this.form.endDate;
      this.allParams.ladderPriceId = this.form.ladderPriceId;
      this.allParams.unitPriceType = this.form.unitPriceType;
      this.allParams.brand = this.form.brand;
      this.allParams.partNumber = this.form.partNumber;
      this.allParams.idList = this.brandId;
      deleteInventory(this.allParams).then((res) => {
        if (res.success) {
          this.$message.success("库存信息已删除");
          this.dialogDelVisible = false;
          this.allParams.startDate = "";
          this.allParams.endDate = "";
          this.allParams.status = "";
          this.allParams.inventoryHome = "";
          this.allParams.ladderPriceId = "";
          this.allParams.unitPriceType = "";
          this.allParams.brand = "";
          this.allParams.idList = [];
          this.allParams.partNumber = "";
          this.allParams.isAll = false;
          this.doRefresh();
        }
      });
    },
    closeApply() {
      this.$refs.applyform.resetFields();
      this.applyform.validityDateStart = '';
      this.applyform.validityDateEnd = "";
      // console.log(this.applyform,'this.applyform');
    },
    // 更新时间
    updateTime() {
      if (this.selectrow.length >= 1) {
        let arr = [];
        this.selectrow.map((val) => {
          arr.push(val.id);
        });
        this.dialogUpdateVisible = true;
        this.brandId = arr;
        console.log(this.brandId);
      } else {
        // this.isdisabled = true;
        // this.$message.warning('请选中至少一行的库存信息进行操作')
      }
    },
    getUpdateSubmit() {
      this.allParams.inventoryHome = this.form.inventoryHome;
      this.allParams.status = this.form.status;
      this.form.startDate = this.form.createDate[0];
      this.form.endDate = this.form.createDate[1];
      this.allParams.startDate = this.form.startDate;
      this.allParams.endDate = this.form.endDate;
      this.allParams.ladderPriceId = this.form.ladderPriceId;
      this.allParams.unitPriceType = this.form.unitPriceType;
      this.allParams.brand = this.form.brand;
      this.allParams.partNumber = this.form.partNumber;
      this.allParams.idList = this.brandId;
      updateInventoryDate(this.allParams).then((res) => {
        if (res.success) {
          this.$message.success(res.message);
          this.dialogUpdateVisible = false;
          this.doRefresh();;
          this.allParams.startDate = "";
          this.allParams.endDate = "";
          this.allParams.status = "";
          this.allParams.inventoryHome = "";
          this.allParams.ladderPriceId = "";
          this.allParams.unitPriceType = "";
          this.allParams.brand = "";
          this.allParams.idList = [];
          this.allParams.partNumber = "";
          this.allParams.isAll = false;
        } else {
          this.$message.error(res.message);
        }
      });
    },
    // 上架
    putOnShelves() {
      if (this.selectrow.length >= 1) {
        let arr = [];
        let arrStatus = [];
        this.selectrow.map((val) => {
          arr.push(val.id);
          arrStatus.push(val.status);
        });
        let setArr = [...new Set(arrStatus)];
        console.log(setArr,'setArrsetArrsetArr');
        if (setArr.length > 1) {
          this.$message.warning("该库存信息无法操作");
          return false;
        }
        console.log(arr, "arrarr");
        this.allParams.idList = arr;
        this.allParams.updateStatus = 1;
        this.allParams.inventoryHome = this.form.inventoryHome;
        this.allParams.status = this.form.status;
        this.form.startDate = this.form.createDate[0];
        this.form.endDate = this.form.createDate[1];
        this.allParams.startDate = this.form.startDate;
        this.allParams.endDate = this.form.endDate;
        this.allParams.ladderPriceId = this.form.ladderPriceId;
        this.allParams.unitPriceType = this.form.unitPriceType;
        this.allParams.brand = this.form.brand;
        this.allParams.partNumber = this.form.partNumber;
        updateStatusList(this.allParams).then((res) => {
          console.log(res, "下架");
          if (res.success) {
            this.$message.success("上架成功");
            this.isShelvesdisabled = true;
            this.doQuery();
            this.allParams.idList = [];
            this.allParams.updateStatus = "";
            this.allParams.inventoryHome = "";
            this.allParams.status = "";
            this.allParams.startDate = "";
            this.allParams.endDate = "";
            this.allParams.ladderPriceId = "";
            this.allParams.unitPriceType = "";
            this.allParams.brand = "";
            this.allParams.isAll = false;
            this.allParams.partNumber = "";
            console.log(
              this.allParams,
              " this.shelvesParams this.shelvesParams"
            );
          } else {
            this.$message.error(res.message);
          }
        });
        console.log(arr);
      }
    },
    // 下架
    lowerShelf() {
      if (this.selectrow.length >= 1) {
        let arr = [];
        let arrStatus = [];
        this.selectrow.map((val) => {
          arr.push(val.id);
          arrStatus.push(val.status);
        });
        let setArr = [...new Set(arrStatus)];
        console.log(setArr,'setArrsetArrsetArr');
        if (setArr.length > 1) {
          this.$message.warning("该库存信息无法操作");
          return false;
        }
        this.allParams.idList = arr;
        this.allParams.updateStatus = 0;
        this.allParams.inventoryHome = this.form.inventoryHome;
        this.allParams.status = this.form.status;
        this.form.startDate = this.form.createDate[0];
        this.form.endDate = this.form.createDate[1];
        this.allParams.startDate = this.form.startDate;
        this.allParams.endDate = this.form.endDate;
        this.allParams.ladderPriceId = this.form.ladderPriceId;
        this.allParams.unitPriceType = this.form.unitPriceType;
        this.allParams.brand = this.form.brand;
        this.allParams.partNumber = this.form.partNumber;
        updateStatusList(this.allParams).then((res) => {
          console.log(res, "下架");
          if (res.success) {
            this.$message.success("下架成功");
            this.isowerdisabled = true;
            this.doQuery();
            this.allParams.idList = [];
            this.allParams.updateStatus = "";
            this.allParams.inventoryHome = "";
            this.allParams.status = "";
            this.allParams.startDate = "";
            this.allParams.endDate = "";
            this.allParams.ladderPriceId = "";
            this.allParams.unitPriceType = "";
            this.allParams.isAll = false;
            this.allParams.brand = "";
            this.allParams.partNumber = "";
          } else {
            this.$message.error(res.message);
          }
        });
        // console.log(arr);
      }
    },
    // 编辑
    getEdit() {
      if (this.selectrow.length == 1) {
        var arr = this.selectrow[0].id;
        this.allParams.idList = [];
        this.allParams.idList.push(arr);
        // this. getPriceByMoq(this.allParams.idList);
        this.allParams.inventoryHome = this.form.inventoryHome;
        this.allParams.status = this.form.status;
        this.form.startDate = this.form.createDate[0];
        this.form.endDate = this.form.createDate[1];
        this.allParams.startDate = this.form.startDate;
        this.allParams.endDate = this.form.endDate;
        this.allParams.ladderPriceId = this.form.ladderPriceId;
        this.allParams.unitPriceType = this.form.unitPriceType;
        this.allParams.brand = this.form.brand;
        this.allParams.partNumber = this.form.partNumber;
        getInventoryList(this.allParams).then((res) => {
          console.log(res, "getInventoryList");
          if (res.success) {
            this.editForm = res.result[0];
            if(this.editForm.packages == '' || this.editForm.packages == null){
              this.isPackDisadled = false;
            }else{
              this.isPackDisadled = true;
            }
            this.allParams.startDate = "";
            this.allParams.endDate = "";
            this.allParams.status = "";
            this.allParams.inventoryHome = "";
            this.allParams.ladderPriceId = "";
            this.allParams.unitPriceType = "";
            this.allParams.brand = "";
            this.allParams.idList = [];
            this.allParams.partNumber = "";
            this.allParams.isAll = false;
            this.doQuery();
            console.log(this.editForm, "this.editForm");
          } else {
            this.$message.error(res.message);
          }
        });
        this.dialogEditVisible = true;
      } else {
        this.$message.warning("请选中一行的库存信息进行操作");
      }
    },
    getEditSubmit(formName) {
      console.log(this.editForm, "111111111111");
      this.$refs[formName].validate((valid) => {
        if (valid) {
          updateInventoryList(this.editForm).then((res) => {
            console.log(res, "this.editForm22222222");
            if (res.success) {
              this.$message.success(res.message);
              this.dialogEditVisible = false;
              this.doQuery();
              this.$refs.editForm.resetFields();
            } else {
              this.$message.error(res.message);
            }
          });
        } else {
          return false;
        }
      });
    },
    closeEdit() {
      this.$refs["editForm"].resetFields();
    },
    handlerBatchPrice(val) {
      console.log( this.priceValidateForm.tableData,' this.priceValidateForm.tableData');
      this.priceValidateForm.tableData.map((item,index) => {
        if(val.tabPosition == 1 ){
          item.ladderPriceId = val.ladderPriceId;
        }else{
          console.log(item,index,'shhuuuuuuuuu22222222');
          if(this.currency == 1 && item.currency == 1){
            item.ladderPriceId = val.ladderAmountPriceId;
          }
          if(this.currency == 2 && item.currency == 2){
            item.ladderPriceId = val.ladderAmountPriceId;
          }
          if(item.currency ==  null){
            item.ladderPriceId = val.ladderAmountPriceId;
          }
        }
      });
    },
    getInverntoryDate(allParams){
      getInventoryList(allParams).then((res) => {
          if (res.success) {
            this.priceValidateForm.tableData = res.result;
            allParams.startDate = "";
            allParams.endDate = "";
            allParams.status = "";
            allParams.inventoryHome = "";
            allParams.ladderPriceId = "";
            allParams.unitPriceType = "";
            allParams.brand = "";
            allParams.partNumber = "";
          }
        });
      // console.log(val,'44444444443333333333');
    },
    getPriceByMoq(arr){
      let params = {
        idList:arr
      }
      LadderPriceByMoq(params).then((res) => {
          console.log(res,'LadderPriceByMoqLadderPriceByMoq');
          if (res.success) {
            this.pricebox = res.result;
            console.log(this.pricebox, "priceStepbox,this.pricebox");
          }
        });
    },
    // 批量配置的数据
    getAmountPriceList(arr,currency){
     
      let priceParams = {
          currency:currency,
          idList:arr
        }
        LadderPriceByAmount(priceParams).then(res=>{
          this.PriceByAmount = res.result;
          // console.log(this.PriceByAmount,'LadderPriceByAmount');
        })
    },
    // 阶梯价格配置
    getPrice() {
      if (this.selectrow.length >= 1) {
        let arr = [];
        this.selectrow.map((val) => {
          arr.push(val.id);
        });
       
        this.allParams.idList = arr;
        this. getPriceByMoq(this.allParams.idList);
        this.getAmountPriceList(this.allParams.idList,this.currency);
        this.allParams.inventoryHome = this.form.inventoryHome;
        this.allParams.status = this.form.status;
        this.form.startDate = this.form.createDate[0];
        this.form.endDate = this.form.createDate[1];
        this.allParams.startDate = this.form.startDate;
        this.allParams.endDate = this.form.endDate;
        this.allParams.ladderPriceId = this.form.ladderPriceId;
        this.allParams.unitPriceType = this.form.unitPriceType;
        this.allParams.brand = this.form.brand;
        this.allParams.partNumber = this.form.partNumber;
        this.getInverntoryDate(this.allParams);
        this.dialogPriceVisible = true;
        }
    },
    showPriceDate(data){
      console.log(data,'rrrrrrrrrrrrr');
      this.priceAmountDate = data;
    },
    showTablePriceDate(data){
      this.priceTableAmountDate = data;
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        if(this.priceAmountDate != ''){
          const _row = this.flitterData(this.priceAmountDate).one[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col,
          };
        }
      }
    },
    objectTableSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        if(this.priceTableAmountDate != ''){
          const _row = this.flitterData(this.priceTableAmountDate).one[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col,
          };
        }
      }
    },
    /**合并表格的第一列，处理表格数据 */
    flitterData(arr) {
      // console.log(arr,'arrrrrrrr');
      let spanOneArr = [];
      let concatOne = 0;
      arr.forEach((item, index) => {
        if (index === 0) {
          spanOneArr.push(1);
        } else {
        //注意这里的quarterly是表格绑定的字段，根据自己的需求来改
          if (item.maxPrice === arr[index - 1].maxPrice && item.minPrice === arr[index - 1].minPrice) {
            //第一列需合并相同内容的判断条件
            spanOneArr[concatOne] += 1;
            spanOneArr.push(0);
          } else {
            spanOneArr.push(1);
            concatOne = index;
          }
        }
      });
      return {
        one: spanOneArr,
      };
    },
    getPriceSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log(this.priceValidateForm.tableData, "this.selectedItem");
          if (this.price.batch == false) {
            this.priceValidateForm.tableData.map((item, index) => {
              this.inventoryList[index] = {};
              this.$set(this.inventoryList[index], "id", item.id);
              this.$set(
                this.inventoryList[index],
                "ladderPriceId",
                item.ladderPriceId
              );
            });
          } else {
            this.priceValidateForm.tableData.map((item, index) => {
              this.inventoryList[index] = {};
              this.$set(this.inventoryList[index], "id", item.id);
              this.$set(
                this.inventoryList[index],
                "ladderPriceId",
                item.ladderPriceId
              );
            });
          }
          this.inventoryList = this.inventoryList.filter(item=>item.ladderPriceId != '')
          // console.log(this.inventoryList,'this.inventoryListthis.inventoryList111');
          if(this.inventoryList.length > 0){
            let params = {
              inventoryList: this.inventoryList,
            };
            console.log(params, "paramsparamsparams");
            setLadderPrice(params).then((res) => {
              console.log(res, "阶梯价格");
              if (res.success) {
                this.$message.success("提交成功");
                this.dialogPriceVisible = false;
                this.doQuery();
                this.price.batch = true;
                this.price.ladderPriceId = "";
                this.price.ladderAmountPriceId = '';
              } else {
                this.$message.error(res.message);
              }
            });
          }else{
            this.dialogPriceVisible = false;
          }
         
        } else {
          // console.log('error submit!!');
          return false;
        }
      });
    },
    closePrice() {
      this.price.batch = true;
      this.$refs.priceValidateForm.clearValidate();
      this.price.ladderPriceId = "";
      this.price.ladderAmountPriceId = '';
    },
    // 批量导出
    exportToExcel() {
      if (this.selectrow.length >= 1) {
        let arr = [];
        this.selectrow.map((val) => {
          arr.push(val.id);
        });
        this.allParams.idList = arr;
        this.allParams.inventoryHome = this.form.inventoryHome;
        this.allParams.status = this.form.status;
        this.form.startDate = this.form.createDate[0];
        this.form.endDate = this.form.createDate[1];
        this.allParams.startDate = this.form.startDate;
        this.allParams.endDate = this.form.endDate;
        this.allParams.ladderPriceId = this.form.ladderPriceId;
        this.allParams.unitPriceType = this.form.unitPriceType;
        this.allParams.brand = this.form.brand;
        this.allParams.partNumber = this.form.partNumber;
      }
      batchExport(this.allParams).then((res) => {
        if (res.success) {
          require.ensure([], () => {
            const {
              exportJsonToExcel,
              formatJson,
            } = require("./execl/Export2Excel");
            // excel表中要显示的标题头
            const tHeader = [
              "型号",
              "品牌",
              "数量",
              "封装",
              "批次",
              "包装",
              "MOQ",
              "MPQ",
              "币种",
              "价格类型",
              "起订量",
              "单价",
              "库存所在地",
            ];
            // 导出的表头字段名
            const filterVal = [
              "partNumber",
              "brand",
              "count",
              "packages",
              "batch",
              "packing",
              "moq",
              "mpq",
              "currency",
              "unitPriceType",
              "mqList",
              "unitPriceList",
              "inventoryHome",
            ];
            let newList = res.result;
            newList.map((item) => {
              if (item.currency == 1) {
                item.currency = "人民币";
              }
              if (item.currency == 2) {
                item.currency = "美元";
              }
              if (item.packing == 1) {
                item.packing = "卷带(TR)";
              }
              if (item.packing == 2) {
                item.packing = "Pack";
              }
              if (item.unitPriceType == 1) {
                item.unitPriceType = "单一价格";
              }
              if (item.unitPriceType == 2) {
                item.unitPriceType = "阶梯价格";
              }
              if (item.mqList == null) {
                item.mqList = "-";
              }
              if (item.inventoryHome == 1) {
                item.inventoryHome = "中国大陆";
              }
              if (item.inventoryHome == 2) {
                item.inventoryHome = "中国香港";
              }
              if (item.inventoryHome == 2) {
                item.inventoryHome = "中国香港";
              }
              if (item.unitPriceType == 2) {
                item.unitPrice = "";
              }
            });
            console.log(
              newList,
              "newListnewListnewListnewListnewListnewListnewListnewListnewList"
            );
            const data = formatJson(filterVal, newList);
            exportJsonToExcel(tHeader, data, "库存信息");
          });
          this.allParams.startDate = "";
          this.allParams.endDate = "";
          this.allParams.status = "";
          this.allParams.inventoryHome = "";
          this.allParams.ladderPriceId = "";
          this.allParams.unitPriceType = "";
          this.allParams.brand = "";
          this.allParams.idList = [];
          this.allParams.partNumber = "";
          this.allParams.isAll = false;
        } else {
          this.$message.error(res.message);
        }
      });
    },
    // 批量配置下拉框选中
  },
  watch: {
    price: {
      handler(val, old) {
        console.log(val, "33333333333333333");
        if (val.batch) {
          this.handlerBatchPrice(val);
          this.$forceUpdate();
        }
      },
      immediate: true,
      deep: true,
    },
    currency:{
      handler(val,old){
        if(this.allParams.idList.length !=0){
          this.price.ladderAmountPriceId = '';
          this.getAmountPriceList(this.allParams.idList,val);
        }
        console.log(val,'5555');
      },
      immediate:true,
      deep:true,
    }
  },
};
</script>

<style lang="scss" scoped>
.manage-stock {
  height: calc(100vh - 120px);
  .manage-stock-header {
    margin: 5px 0 15px;
    display: flex;
    ::v-deep .el-form-item .el-form-item__label{
      background-color: #F0F0F0 !important;
      text-align: center;
      font-weight: 400;
      color: #1A2035;
      border-radius: 2px 0 0 2px;
    
    }
    .label-name-col{
      ::v-deep  .el-form-item__label{
        letter-spacing: 18px !important;
        text-align: right !important;
      }
      
    }
    .el-col-5 {
      text-align: right;
    }
    .btn {
      margin-bottom: 23px;
      // }
    }
  }
  .oper-tit {
    font-size: 14px;
    font-weight: 400;
    color: #008fff;
    line-height: 22px;
    text-align: center;
    cursor: pointer;
  }
  ::v-deep .el-icon-date:before{
        margin-right: 10px;
    }
  .status-box {
    line-height:32px !important;
    height: 32px !important;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .circle {
    width: 5px;
    height: 5px;
    background: #c8c8c8;
    border-radius: 50%;
    margin-right: 5px;
  }
  .partNumber-box {
    line-height: 32px !important;
    height: 32px !important;
    display: flex;
    align-items: center;
    img {
      width: 24px;
      height: 22px;
      display: block;
    }
    span{
      width: 24px;
      display: block;
    }
    p{
      width: 100%;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;

    }
  }
  .circle-col {
    width: 5px;
    height: 5px;
    background: #44d7b6;
    border-radius: 50%;
    margin-right: 5px;
  }
  .header {
    display: flex;
    align-items: center;
    margin: 15px 0;
  }
  .currency-box{
    margin-bottom: 15px;
  }
  .select-model {
    width: 18%;
    margin-left: 10px;
  }
  .dialog-footer {
    text-align: center;
  }
  .del-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    img {
      width: 60px;
      height: 60px;
      display: block;
    }
  }
  .del-icon {
    font-size: 50px;
    color: #2348E8;
  }
  .del-content {
    font-size: 24px;
    font-weight: 600;
    color: #333333;
    line-height: 22px;
    margin-bottom: 30px;
  }
  .del-tips {
    font-size: 16px;
    color: #333333;
    line-height: 22px;
  }
  .update-content {
    font-size: 24px;
    font-weight: 600;
    color: #333333;
    line-height: 22px;
    margin: 20px 0 0;
  }
  .tips {
    font-size: 14px;
    font-weight: 400;
    color: rgba(119, 119, 119, 0.65);
    line-height: 22px;
  }
  .editForm{
    height: 96.5%;
  }
  .type-box {
    text-align: left;
    margin: 0;
    height: 32px !important;
    line-height:32px !important;
  }
  .pricetype-box{
    display: flex;
    justify-content: space-between;
    align-items:center;
    padding-right: 21px;
    margin:0;
    span{
      display: block;
      font-size: 12px;
      font-weight: 400;
      color: #1A2035;
      line-height: 32px;
      &:last-child{
        font-size: 12px;
        font-weight: 400;
        color: #00AB2B;
        line-height: 32px;
      }
    }
  }
  .type-look {
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin:0;
    // color: #008fff;
    cursor: pointer;
    span{
      display: block;
      &:last-child{
        display: flex;
        font-size: 12px;
        font-weight: 400;
        color: #00AB2B;
        line-height: 17px;
        img{
          width: 17px;
          height: 17px;
          display: block;
          margin-left: 3px;
        }
      }
    }

    img{
      display: block;
    }
  }
  .manage-stock-meduim {
    // margin: 10px 24px 10px;
  }
  .manage-stock-footer {
    box-sizing: border-box;
    border-radius: 8px;
    // cursor: pointer;
    .table-box {
      width: 100%;
    }
  }
  .price-box {
    height: 32px !important;
    line-height: 32px !important;
    position: relative;
  }
  .price-list {
    width: 300px;
    height: auto;
    position: absolute;
    top: 0;
    right: 0;
    z-index: 99;
  }
  .tips-box {
    font-size: 12px;
    font-weight: 400;
    color: #999;
    p{
      margin: 10px 0;
      &:last-child{
        margin: 0px 0 10px 36px;
        
      }
    }
  }
  // .el-form-item__content{
  //   ::v-deep .el-range-editor.el-input__inner{
  //     width: 97%;
  //   }
  // }

  .el-col-4 {
    text-align: right;
    padding-right: 10px;
  }
  .el-form-item--small .el-form-item__label {
    font-weight: 400;
  }
  .cancel-dialog {
    ::v-deep .el-dialog:not(.is-fullscreen) {
      margin-top: 28vh !important;
      .el-dialog__header {
        display: none;
      }
    }
  }
 ::v-deep .el-input--small .el-input__inner{
   color: #1A2035 !important;
  }
  .add-dialog {
    ::v-deep .el-drawer__body{
      .el-form-item .el-form-item__label {
        color: #999 !important;
        font-size: 12px !important;
        text-align: left !important;
      }
      .el-form-item.is-required:not(.is-no-asterisk) > .el-form-item__label:before, .el-form-item.is-required:not(.is-no-asterisk) .el-form-item__label-wrap > .el-form-item__label:before {
          content: "*";
          color: #ff4949;
          margin-right: 4px;
      }
      .demo-drawer__footer{
        text-align: center;
      }
      .el-form-item > .el-form-item__label:before {
        content: "";
        margin-right: 6px;
      }
    }
  }
}
.apply-dialog {
  ::v-deep .el-form-item .el-form-item__label{
    text-align: left;
  }
  .applyform{
    width: 72%;
    margin: auto;
    margin-bottom: 100px;
  }
  .line{
      text-align: center;
      display:block;
  }
  .el-form-item--small.el-form-item{
    margin-bottom: 8px !important;
  }
  ::v-deep .el-textarea .el-input__count{
    bottom: -4px !important;
  }
  ::v-deep .el-textarea__inner{
    min-height: 120px !important;
  }
  ::v-deep .el-date-editor.el-input{
        width: 100% !important;
    }
    ::v-deep .el-input__prefix {
        position: absolute;
        left: 88% !important; // left根据实际情况定值
        top: 0;
    }
    ::v-deep .el-input__suffix-inner{
        display: none;
    }
  // ::v-deep .el-dialog:not(.is-fullscreen) {
  //   margin-top: 30vh !important;
  // }
  
}
.price-dialog{
  ::v-deep .el-dialog .el-dialog__body{
    padding:24px !important;
    .el-form-item--small.el-form-item{
      margin-bottom: 0 !important;
    }
  }
}
</style>